import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
from sklearn.impute import SimpleImputer
import pandas as pd
import numpy as np

# 导入数据
pop = pd.read_csv(r"C:\Users\Lenovo\Desktop\Insightful & Vast USA Statistics\data_after_initsolve.csv", usecols = ['pop'])
ALand = pd.read_csv(r"C:\Users\Lenovo\Desktop\Insightful & Vast USA Statistics\data_after_initsolve.csv", usecols = ['ALand'])

# 用中位数填补缺失值
imp_median = SimpleImputer(strategy = "median")

# fit_transform一步完成调取结果
pop = imp_median.fit_transform(pop)
ALand = imp_median.fit_transform(ALand)

Population_Density = np.divide(pop,ALand)
Population_Density = pd.DataFrame(Population_Density)
# print(Population_Density)

# 导出人口密度
Population_Density.to_csv(r"C:\Users\Lenovo\Desktop\Insightful & Vast USA Statistics\每个UID的人口密度.csv")
